<template>
    <div>
        <el-form  :model="model" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

            <el-form-item label="缺陷描述" prop="Reason">
               <el-input type="textarea" :rows="2.5" placeholder="请描述缺陷" v-model="model.Remark"></el-input>
            </el-form-item>

            <el-form-item label="缺陷等级" prop="LevelName">
                <el-select v-model="model.LevelName" placeholder="请选择缺陷等级">
                    <el-option label="微瑕" value="微瑕"></el-option>
                    <el-option label="轻度缺陷" value="轻度缺陷"></el-option>
                    <el-option label="严重缺陷" value="严重缺陷"></el-option>
                    <el-option label="致命缺陷" value="致命缺陷"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="检测项类型" prop="Classify">
                <el-select v-model="model.Classify" placeholder="请选择检测项类型" style="width: 160px;">
                    <el-option v-for="item in QcProjectClassifyList" :key="item.Id" :label="item.ProjectName" :value="item.ProjectName"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item class="page-box-footer">
                <el-button type="primary" @click="submitForm">{{ isUpdate?'立即保存':'立即创建' }}</el-button>
                <el-button @click="resetForm">重置</el-button>
            </el-form-item>



        </el-form>
    </div>
</template>


<script>
export default{
    props:{
        model: {
            required: true,
            type: Object
        },
        isUpdate: {
            required: true,
            type: Boolean
        }
    },
    mounted(){
        this.getQcProjectClassifyData();
    },
    data(){
        return{
            //检测项目分类数据
            QcProjectClassifyList:[],
            UnitMeasureList:[],
            rules: {
                LevelName: { required: true, message: '请选择缺陷等级', trigger: 'blur' },
                Classify: { required: true, message: '请选择检测分类', trigger: 'blur' },
                Remark: { required: true, message: '请描述缺陷', trigger: 'blur' },
            }
        }
    },
    created(){
        this.GetQcProjectLevelAll();
    },
    methods:{
        submitForm(){
            this.$refs['ruleForm'].validate((valid)=>{
                if(valid){
                    if(this.isUpdate){
                        this.put();
                    }
                    else{
                        this.add();
                    }
                } else{
                    this.showNotify('请输入必填项');
                    return false;
                }
            });
        },
        resetForm() {
            this.$refs['ruleForm'].resetFields();
        },

        //新增
        add(){
            this.$http.postForm('/api/QcProjectLevel',{model:this.model},{loading:this.$loading()})
            .then(res=>{
                this.$emit('callback');
            })
        },

        //修改
        put(){
            this.$http.putForm('/api/QcProjectLevel',{model:this.model},{loading:this.$loading()})
            .then((res)=>{
                this.$emit('callback');
            })
        },
        GetQcProjectLevelAll(){
            this.$http.get('/api/QcProjectLevel/GetAll')
            .then(res=>{
                this.UnitMeasureList=res.Data ;
            })
        },

        //获取检测项分类数据
        getQcProjectClassifyData(){
            this.$http.get('/api/QcProjectClassify/GetAll')
                .then(res=>{
                    this.QcProjectClassifyList=res.Data;
            })
            
        },

    }
}

</script>

<style scoped>

</style>